package lambda;

import org.junit.Test;

import java.util.Comparator;

/**
 * @author mubei
 * @date 2021/11/20
 * @description  lambda 的使用举例
 */
public class Test01 {

    public static void main(String[] args) {
        Runnable r2 = ()-> System.out.println("这个");
        r2.run();
    }



    @Test
    public void test1(){
            new Runnable() {
                @Override
                public void run() {
                    System.out.println("匿名类");
                }
            }.run();
    }


    @Test
    public void test2(){
        Comparator<Integer> comparator = new Comparator<Integer>(){
            @Override
            public int compare(Integer o1 , Integer o2){
                return Integer.compare(o1,o2);
            }
        };

        System.out.println(comparator.compare(10,21));

        System.out.println("-----------");
        Comparator<Integer> comparator1 = (o1,o2)->Integer.compare(o1,o2);
        System.out.println(comparator1.compare(10,21));


        System.out.println("-----------");
        Comparator<Integer> comparator2 = Integer::compare;
        System.out.println(comparator2.compare(10,21));
    }
}
